In [1]:
import pypot.dynamixel
import time
In [27]:
ports = pypot.dynamixel.get_available_ports()
if not ports:
raise IOError('no port found!')
print "Ports founds %s" % ports
for port in ports:
print('Connecting on port:', port)
dxl_io = pypot.dynamixel.DxlIO(port)
motors = dxl_io.scan()
print(" %s motors founds : %s\n" % (len(motors),motors))
dxl_io.close()
In [ ]:
#57142 => 1000000
#return_delay_time => 0
def motor_config():
ports = pypot.dynamixel.get_available_ports()
if len(ports) == 1:
print("Connection au port %s" % ports[0])
dxl_io = pypot.dynamixel.DxlIO(ports[0])
print('Scan des moteurs (cela peut prendre quelques secondes)')
motors = dxl_io.scan()
if len(motors) == 1:
print("OK, un seul moteur trouvé : %s" % motors[0])
for k,v in dxl_io.__dict__.items():
print(" - %s : %s" % (k,v))
dxl_io.enable_torque(motors)
dxl_io.set_moving_speed({motors[0]:200})
print("Positionnement du moteur %s à 90° " % motors[0])
dxl_io.set_goal_position({motors[0]:90})
while dxl_io.is_moving((motors[0],))[0]:
time.sleep(0.02)
print("Positionnement du moteur %s à -90° " % motors[0])
dxl_io.set_goal_position({motors[0]:-90})
while dxl_io.is_moving((motors[0],))[0]:
time.sleep(0.02)
print("Positionnement du moteur %s à 0° " % motors[0])
dxl_io.set_goal_position({motors[0]:0})
while dxl_io.is_moving((motors[0],))[0]:
time.sleep(0.02)
dxl_io.disable_torque(motors)
target_id = raw_input("Changer l'id du moteur %s : " % motors[0])
try:
target_id = int(target_id)
dxl_io.change_id({motors[0]:target_id})
print("ID modifié")
except ValueError:
print("ID non modifié")
dxl_io.close()
else:
print("Erreur, %s moteurs conncectés : %s" % (len(motors), motors))
else :
print("Erreur, %s ports trouvés : %s" % (len(ports),ports))
motor_config()
In [ ]: